package kr.saeildamil.androidforstudy2.ch24;

import kr.saeildamil.androidforstudy2.R;
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class ValueAnimatorTest02 extends Activity {
	Button mBtn;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch24_valueanimatortest);

		mBtn = (Button) findViewById(R.id.ch24_valueanimatortest_animbtn);

	}

	public void mOnClick(View v) {
		ValueAnimator animator = ValueAnimator.ofInt(150, 480);
		animator.setDuration(2000);
		animator.setInterpolator(null);
		animator.setRepeatCount(1);
		animator.setRepeatMode(ValueAnimator.REVERSE);
		animator.addListener(new AnimatorListener() {
			
			@Override
			public void onAnimationStart(Animator animation) {
				Toast.makeText(ValueAnimatorTest02.this, "Start Animation", 0).show();
			}
			
			@Override
			public void onAnimationRepeat(Animator animation) {
				
			}
			
			@Override
			public void onAnimationEnd(Animator animation) {
				Toast.makeText(ValueAnimatorTest02.this, "The End", 0).show();
				
			}
			
			@Override
			public void onAnimationCancel(Animator animation) {
				
			}
		});
		
		animator.addUpdateListener(new AnimatorUpdateListener() {
			
			@Override
			public void onAnimationUpdate(ValueAnimator animation) {
				mBtn.setWidth((Integer) animation.getAnimatedValue());
			}
		});
		
		animator.start();
	}
}
